package cn.yangyumanage.model;

import java.io.IOException;
import java.util.List;

import cn.yangyumanage.application.DataApplication;
import cn.yangyumanage.bean.DouBanSearchItemBean;
import cn.yangyumanage.bean.util.DouBanSearchContainer;
import cn.yangyumanage.callback.DataCallBack;
import cn.yangyumanage.callback.HttpCallBack;
import cn.yangyumanage.config.IpConfig;
import cn.yangyumanage.http.HttpClient;
import cn.yangyumanage.util.Aes;

public class DouBanSearchHttpModel implements BaseModel {

    //获取搜索内容（豆瓣）
    public void getSearchContent(String searchContent, DataCallBack dataCallBack) {
        String url = IpConfig.AGREEMENT + IpConfig.SERVERIP + "/films/douban?searchContent=" + searchContent;
        HttpClient.asyncGet(url, new HttpCallBack() {
            @Override
            public void onSuccess(String msg) {
                try {
                    String decrypt = Aes.decrypt(msg);
                    DouBanSearchContainer container = DataApplication.gson.fromJson(decrypt, DouBanSearchContainer.class);
                    List<DouBanSearchItemBean> datas = container.getData();
                    dataCallBack.getData(datas);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(IOException e) {
                e.printStackTrace();
            }
        }, HttpClient.ADMIN);
    }

    @Override
    public void onDestroy() {

    }
}
